<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="./js/vue.min.js"></script>
    <title>计算属性的setter和getter</title>
</head>
<body>
<div id="app">
    <!--计算属性-->
    <h2>{{fullName}}</h2>

    <pre>app.fullName = "LIu yifei"</pre>
</div>
</body>
<script>
    const app = new Vue({
        el:"#app",
        data:{
            firstName:"Wong",
            lastName:"Ho"
        },
        computed:{
            fullName:{
                set:function (newValue) {
                    console.log("-----");
                    const names = newValue.split(" ");
                    console.log(names[0]+","+names[1]);
                    this.firstName = names[0];
                    this.lastName = names[1];
                },
                get:function () {
                    return this.firstName + " " + this.lastName;
                }

            }
        }
    })
</script>
</html>